package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.annotation.AutoFill;
import com.sky.dto.CategoryPageQueryDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Category;
import com.sky.entity.Dish;
import com.sky.entity.DishFlavor;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface DishMapper {

    /**
     * 根据分类id查询菜品数量
     * @param categoryId
     * @return
     */
    @Select("select count(id) from dish where category_id = #{categoryId}")
    Integer countByCategoryId(Long categoryId);

    /**
     * 根据id查询菜的数据
     * @param id
     * @return
     *
     */
    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);

    /**
     *
     * @param CategoryId
     * @return
     */
    @Select("select * from dish where category_id = #{CategoryId}")
    List<Dish>getByCategoryId(Long CategoryId);

    /**
     * 根据CategoryId和状态得到数据
     * @param dish
     * @return
     */
    @Select("select * from sky_take_out.dish where category_id = #{categoryId} and status=#{status} ")
    List<Dish>getByCategoryIdAndStatus(Dish dish);
    /**
     * 插入菜品数据
     * @param dish
     */
    @AutoFill(value = OperationType.INSERT)
    void insert(Dish dish);

    /**
     * 分页查询
     * @param
     * @return
     */
    Page<DishVO> pageQuery(DishPageQueryDTO dishPageQueryDTO);

//    /**
//     * 菜品起售、停售
//     * @param id
//     * @param status
//     */
//    @AutoFill(OperationType.UPDATE)
//    @Update("UPDATE dish set dish.status=#{status} where id = #{id}")
//    void setStatus(int status, long id);

    /**
     * 修改菜品
     * @param dish
     */
    @AutoFill(OperationType.UPDATE)
    void changeDish(Dish dish);

    @Delete("delete from dish where id=#{id}")
    void deleteByID(Long id);

    /**
     * 根据菜品ID集合批量删除菜品
     * @param ids
     */
    void deleteByIDs(List<Long> ids);
}
